import Vue from 'vue'
import Router from 'vue-router'
import Approval from './modules/approval.js'
import Attendance from './modules/attendance.js'
import Department from './modules/department.js'
import Employee from './modules/employee.js'
import Permission from './modules/permission.js'
import Role from './modules/role.js'
import Salary from './modules/salary.js'
import Social from './modules/social.js'
Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
]
// 将路由抽离出来
export const asyncRouter = [
  Department, // 组织
  Role, // 角色
  Employee, // 员工
  Permission, // 权限
  Attendance, // 考勤
  Approval, // 审批
  Salary, // 工资
  Social // 社保
]
const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
